package com.lmx.wuzhangshao.ui;

import android.os.Bundle;
import android.widget.FrameLayout;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.lmx.wuzhangshao.R;
import com.lmx.wuzhangshao.base.BaseActivity;
import com.lmx.wuzhangshao.ui.fragment.HomeFragment;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author Leung
 * @date 2020/7/23 20:33
 */
public class MainActivity extends BaseActivity {

    @BindView(R.id.bnv_main_bottomNav)
    BottomNavigationView bnvMainBottomNav;
    @BindView(R.id.fl_main_container)
    FrameLayout flMainContainer;

    private Fragment homeFragment = new HomeFragment();

    public static final String TAG_HOME = "HOME";

    @Override
    protected int setLayoutResId() {
        return R.layout.activity_main;
    }

    @Override
    public boolean isEnableToolBar() {
        return false;
    }

    @Override
    protected String setTitleText() {
        return getString(R.string.app_name);
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);

        bnvMainBottomNav.setOnNavigationItemSelectedListener((item -> {
            onTabItemSelected(item.getItemId());
            return true;
        }));
        onTabItemSelected(R.id.menu_main_home);
    }

    private void onTabItemSelected(int id) {
        switch (id) {
            case R.id.menu_main_home:
                replaceFragment(homeFragment, TAG_HOME);
                break;
//            case R.id.menu_main_dingdan:
//                rlMainToolbar.setBackground(getDrawable(R.drawable.bar_background));
//                tvMainTitle.setText("订单");
//                tvMainLocation.setVisibility(View.GONE);
//                imgBtnMainService.setVisibility(View.GONE);
//                break;
//            case R.id.menu_main_collect:
//                rlMainToolbar.setBackground(getDrawable(R.drawable.bar_background));
//                tvMainTitle.setText("我的收藏");
//                tvMainLocation.setVisibility(View.GONE);
//                imgBtnMainService.setVisibility(View.GONE);
//                break;
//            case R.id.menu_main_user:
//
//
            default:
        }
    }

    private void replaceFragment(Fragment fragment, String tag) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.fl_main_container, fragment, tag);
        transaction.commit();
    }

}
